﻿using System;
using Auxiliary.VecMath;

namespace Simple3DRedactor.Domain
{
    [Serializable]
    public abstract class SceneObject
    {
        protected SceneObject()
        {
            Name = "Object";
            Rotation = Position = Vector3D.Zero;
            Active = true;
        }

        public event Action<SceneObject> Change;
        protected void OnChange()
        {
            if (Change != null) Change(this);
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    OnChange();
                }
            }
        }

        private Vector3D _position;
        public Vector3D Position
        {
            get { return _position; }
            set
            {
                if (_position != value)
                {
                    _position = value;
                    OnChange();
                }
            }
        }

        private Vector3D _rotation;
        public Vector3D Rotation
        {
            get { return _rotation; }
            set
            {
                if (_rotation != value)
                {
                    _rotation = value;
                    OnChange();
                }
            }
        }

        private bool _active;
        public bool Active
        {
            get { return _active; }
            set
            {
                if (_active != value)
                {
                    _active = value;
                    OnChange();
                }
            }
        }

        public abstract TV CreateView<TV>(IObjectViewFactory<TV> factory) where TV : IObjectView;
    }
}
